/**
 * 
 * 起迪科技 Copyright (c) 2014-2018 QiDi,Inc.All Rights Reserved.
 */

package cn.qidisoft.edu.hzjt.controller.twglstudentcorpactivity;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.qidisoft.core.common.log.LoggerAdapter;
import cn.qidisoft.core.common.log.LoggerAdapterFactory;
import cn.qidisoft.core.common.pagination.Page;
import cn.qidisoft.core.common.pagination.PaginationBean;
import cn.qidisoft.core.util.moffice.excel.ExpExcelUtil;
import cn.qidisoft.edu.hzjt.annotation.SysLogger;
import cn.qidisoft.edu.hzjt.constants.Constant;
import cn.qidisoft.edu.hzjt.controller.BaseController;
import cn.qidisoft.edu.hzjt.exception.RPCException;
import cn.qidisoft.edu.hzjt.model.ResponseResult;
import cn.qidisoft.edu.hzjt.model.Student;
import cn.qidisoft.edu.hzjt.model.TwglStudentCorpActivity;
import cn.qidisoft.edu.hzjt.model.TwglStudentCorporation;
import cn.qidisoft.edu.hzjt.model.UserEmployee;
import cn.qidisoft.edu.hzjt.service.ICommonService;
import cn.qidisoft.edu.hzjt.service.ITwglStudentCorpActivityService;
import cn.qidisoft.edu.hzjt.service.ITwglStudentCorporationService;
import cn.qidisoft.edu.hzjt.utils.LogType;

/**
 * 
 * 
 * @author Administrator
 * @version $Id: TwglStudentCorpActivityController.java, v 0.1 2018年11月1日 上午10:50:34 hhl Exp $
 */

@Controller
@RequestMapping(value = "twglStudentCorpActivity")
public class TwglStudentCorpActivityController {
    protected static final LoggerAdapter    LOGGER = LoggerAdapterFactory
        .getLogger(LogType.HZJT_LOGGER.val);
    @Autowired
    private ITwglStudentCorpActivityService twglStudentCorpActivityService;

    @Autowired
    private ITwglStudentCorporationService  twglStudentCorporationService;

    @Autowired
    private ICommonService                  commonService;

    @RequestMapping(value = "/index")
    public String index(ModelMap model, HttpServletRequest request) {
        try {
            Student student = (Student) request.getSession()
                .getAttribute(Constant.LOGIN_CONSOLE_USER);
            TwglStudentCorporation data = new TwglStudentCorporation();
            data.setSzid(student.getXsid());
            List<TwglStudentCorporation> liststmc = twglStudentCorporationService
                .getUseridstmc(data);
            model.addAttribute("liststmc", liststmc);

            request.setAttribute("msg", BaseController.getParameter("msg"));
            BaseController.removeParameter("msg");
        } catch (Exception e) {
            e.printStackTrace();
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }

        return "twglStudentCorpActivity/twglStudentCorpActivityList";
    }

    @RequestMapping(value = "/List")
    @ResponseBody
    public ResponseResult List(ModelMap model, HttpServletRequest request,
                               @RequestParam(value = "rows", required = false) String pageSize,
                               @RequestParam(value = "page", required = false) String currentPage,
                               TwglStudentCorpActivity data) {

        try {
            Student student = (Student) request.getSession()
                .getAttribute(Constant.LOGIN_CONSOLE_USER);
            data.setCreatorid(student.getXsid());
            Page page = new Page();
            page.setCurrPage(currentPage == null ? 0 : Integer.valueOf(currentPage));
            page.setPageSize(pageSize == null ? Constant.PageSize : Integer.valueOf(pageSize));

            BaseController.setSortByColumn(request, "createtime", "desc");
            if (request.getAttribute("orderField").equals("createtime")) {
                data.setOrderField("cc.CreateTime");
            } else if (request.getAttribute("orderField").equals("logo")) {
                data.setOrderField("cc.CreateTime");
            } else if (request.getAttribute("orderField").equals("states")) {
                data.setOrderField("cc.states");
            } else {
                data.setOrderField((String) request.getAttribute("orderField"));
            }
            data.setOrderFlag((String) request.getAttribute("orderFlag"));

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            if (data.getBeginTime1() == null || data.getBeginTime1().equals("")) {
            } else {
                data.setBeginTime(sdf.parse(data.getBeginTime1()));
            }
            if (data.getEndTime1() == null || data.getEndTime1().equals("")) {
            } else {
                data.setEndTime(sdf.parse(data.getEndTime1()));
            }

            PaginationBean<TwglStudentCorpActivity> paginationBean = twglStudentCorpActivityService
                .queryPageList(data, page);
            ResponseResult result = new ResponseResult();
            if (paginationBean.getPageList().isEmpty()) {
                result.setRows(new ArrayList<TwglStudentCorpActivity>());
            } else {
                result.setRows(paginationBean.getPageList());
            }
            result.setTotal(paginationBean.getTotalRecords());
            return result;
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
        return null;
    }

    @RequestMapping(value = "/addInInt", method = RequestMethod.GET)
    public String add(ModelMap model, HttpServletRequest request) {
        try {
            Student student = (Student) request.getSession()
                .getAttribute(Constant.LOGIN_CONSOLE_USER);
            model.addAttribute("xsid", student.getXsid());
            model.addAttribute("xsxm", student.getXm());

            TwglStudentCorporation data = new TwglStudentCorporation();
            data.setSzid(student.getXsid());
            List<TwglStudentCorporation> liststmc = twglStudentCorporationService
                .getUseridstmc(data);
            model.addAttribute("liststmc", liststmc);

            request.setAttribute("msg", BaseController.getParameter("msg"));
            BaseController.removeParameter("msg");
        } catch (Exception e) {
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
        return "twglStudentCorpActivity/add_TwglStudentCorpActivity";
    }

    @RequestMapping(value = "/details", method = RequestMethod.GET)
    public String details(ModelMap model, HttpServletRequest request,
                          @RequestParam(value = "id", required = false) Integer id,
                          @RequestParam(value = "gid", required = false) String gid) {
        try {

            TwglStudentCorpActivity data = new TwglStudentCorpActivity();
            data.setHdid(id);
            data.setGid(gid);
            data = twglStudentCorpActivityService.queryByPK(data);

            Student student = (Student) request.getSession()
                .getAttribute(Constant.LOGIN_CONSOLE_USER);
            TwglStudentCorporation data1 = new TwglStudentCorporation();
            data1.setSzid(student.getXsid());
            List<TwglStudentCorporation> liststmc = twglStudentCorporationService
                .getUseridstmc(data1);
            model.addAttribute("liststmc", liststmc);

            model.addAttribute("data", data);
            return "twglStudentCorpActivity/details_TwglStudentCorpActivity";
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("查询 queryByPK [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(), e.getMessage());
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
    }

    @SysLogger(description = "社团活动管理信息", moduleName = "社团活动管理", method = "新增保存")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public String add(ModelMap model, HttpServletRequest request, TwglStudentCorpActivity data) {
        try {
            Student student = (Student) request.getSession()
                .getAttribute(Constant.LOGIN_CONSOLE_USER);
            data.setCreatorid(student.getXsid());
            data.setCreatorname(student.getXm());
            data.setCreatetime(new Date());

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            data.setHdrq(sdf.parse(data.getBeginTime1()));

            String gid = twglStudentCorpActivityService.add(data);

            model.addAttribute("gid", gid);
            return "redirect:/twglStudentCorpActivity/details";
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
    }

    @SysLogger(description = "社团活动管理信息", moduleName = "社团活动管理", method = "新增保存")
    @RequestMapping(value = "/addSaveContinue", method = RequestMethod.POST)
    public String addSaveContinue(ModelMap model, HttpServletRequest request,
                                  TwglStudentCorpActivity data) {
        try {
            Student student = (Student) request.getSession()
                .getAttribute(Constant.LOGIN_CONSOLE_USER);
            data.setCreatorid(student.getXsid());
            data.setCreatorname(student.getXm());
            data.setCreatetime(new Date());

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            data.setHdrq(sdf.parse(data.getBeginTime1()));

            twglStudentCorpActivityService.add(data);

            BaseController.setParameter("msg", "添加成功");
            return "redirect:addInInt";
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("添加信息 add [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(), e.getMessage());
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
    }

    @SysLogger(description = "社团活动管理信息", moduleName = "社团活动管理", method = "提交")
    @RequestMapping(value = "/btnSubmit")
    public String btnSubmit(ModelMap model, HttpServletRequest request,
                            @RequestParam(value = "id", required = false) Integer id) {
        try {

            TwglStudentCorpActivity data = new TwglStudentCorpActivity();
            data.setHdid(id);
            data = twglStudentCorpActivityService.queryByPK(data);
            data.setStates(1);
            data.setAuditsuggestion(null);
            data.setAuditorid(null);
            data.setAuditorname(null);
            data.setAudittime(null);
            twglStudentCorpActivityService.update(data);

            model.addAttribute("id", id);
            return "redirect:/twglStudentCorpActivity/details";
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
    }

    @SysLogger(description = "社团活动管理信息", moduleName = "社团活动管理", method = "提交")
    @RequestMapping(value = "/updatebtnSubmit")
    public String updatebtnSubmit(ModelMap model, HttpServletRequest request,
                                  TwglStudentCorpActivity data) {
        try {

            Student student = (Student) request.getSession()
                .getAttribute(Constant.LOGIN_CONSOLE_USER);
            TwglStudentCorporation data1 = new TwglStudentCorporation();
            data1.setSzid(student.getXsid());
            List<TwglStudentCorporation> liststmc = twglStudentCorporationService
                .getUseridstmc(data1);
            model.addAttribute("liststmc", liststmc);

            data.setCreatorid(student.getXsid());
            data.setCreatorname(student.getXm());
            data.setCreatetime(new Date());
            twglStudentCorpActivityService.update(data);

            model.addAttribute("id", data.getHdid());
            return "redirect:/twglStudentCorpActivity/details";
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
    }

    @RequestMapping(value = "/updateToview", method = RequestMethod.GET)
    public String updateToview(ModelMap model, HttpServletRequest request,
                               @RequestParam(value = "id") Integer id) {
        try {

            Student student = (Student) request.getSession()
                .getAttribute(Constant.LOGIN_CONSOLE_USER);
            TwglStudentCorporation data1 = new TwglStudentCorporation();
            data1.setSzid(student.getXsid());
            List<TwglStudentCorporation> liststmc = twglStudentCorporationService
                .getUseridstmc(data1);
            model.addAttribute("liststmc", liststmc);

            TwglStudentCorpActivity data = new TwglStudentCorpActivity();
            data.setHdid(id);
            data = twglStudentCorpActivityService.queryByPK(data);

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            data.setBeginTime1(sdf.format(data.getHdrq()));

            model.addAttribute("data", data);

            return "twglStudentCorpActivity/update_TwglStudentCorpActivity";
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("查询 queryByPK [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(), e.getMessage());
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
    }

    @RequestMapping(value = "/registration", method = RequestMethod.GET)
    public String registration(ModelMap model, HttpServletRequest request,
                               @RequestParam(value = "id") Integer id) {
        try {

            Student student = (Student) request.getSession()
                .getAttribute(Constant.LOGIN_CONSOLE_USER);
            TwglStudentCorporation data1 = new TwglStudentCorporation();
            data1.setSzid(student.getXsid());
            List<TwglStudentCorporation> liststmc = twglStudentCorporationService
                .getUseridstmc(data1);
            model.addAttribute("liststmc", liststmc);

            TwglStudentCorpActivity data = new TwglStudentCorpActivity();
            data.setHdid(id);
            data = twglStudentCorpActivityService.queryByPK(data);

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            data.setBeginTime1(sdf.format(data.getHdrq()));
            model.addAttribute("data", data);

            request.setAttribute("msg", BaseController.getParameter("msg"));
            BaseController.removeParameter("msg");

            return "twglStudentCorpActivity/twglStudentCorpActivity_registration";
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("查询 queryByPK [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(), e.getMessage());
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
    }

    @SysLogger(description = "社团活动管理信息", moduleName = "社团活动管理", method = "登记")
    @RequestMapping(value = "/registrationUpdate")
    public String registrationUpdate(ModelMap model, HttpServletRequest request,
                                     TwglStudentCorpActivity data) {
        try {

            TwglStudentCorpActivity twglStudentCorpActivity = new TwglStudentCorpActivity();
            twglStudentCorpActivity.setHdid(data.getHdid());
            twglStudentCorpActivity = twglStudentCorpActivityService
                .queryByPK(twglStudentCorpActivity);
            twglStudentCorpActivity.setCjry(data.getCjry());
            twglStudentCorpActivity.setHdzy(data.getHdzy());
            twglStudentCorpActivityService.update(twglStudentCorpActivity);

            BaseController.setParameter("msg", "保存成功");
            model.addAttribute("id", data.getHdid());
            return "redirect:/twglStudentCorpActivity/registration";
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("查询 queryByPK [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(), e.getMessage());
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
    }

    @SysLogger(description = "社团活动管理信息", moduleName = "社团活动管理", method = "修改")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public String update(ModelMap model, HttpServletRequest request, TwglStudentCorpActivity data) {
        try {

            Student student = (Student) request.getSession()
                .getAttribute(Constant.LOGIN_CONSOLE_USER);
            data.setCreatorid(student.getXsid());
            data.setCreatorname(student.getXm());

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            data.setHdrq(sdf.parse(data.getBeginTime1()));

            if (data.getAudittime1() == null || data.getAudittime1().equals("")) {
                data.setAudittime(null);
            } else {
                SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd hh:mm");
                data.setAudittime(sdf2.parse(data.getAudittime1()));
            }
            data.setStates(0);
            twglStudentCorpActivityService.update(data);
            BaseController.setParameter("msg", "保存成功");
            return "redirect:index";
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("查询 update [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(), e.getMessage());
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
    }

    @SysLogger(description = "社团活动管理信息", moduleName = "社团活动管理", method = "删除")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public String delete(ModelMap model, HttpServletRequest request) {
        try {
            String[] idList = request.getParameter("idList").split(",");
            TwglStudentCorpActivity data = new TwglStudentCorpActivity();
            data.setIds(idList);
            twglStudentCorpActivityService.delete(data);
            BaseController.setParameter("msg", "删除成功");
            return "redirect:index";
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("删除 delete [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(), e.getMessage());
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
    }

    /**
     * 下载
     * 
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */

    @RequestMapping(value = "/export")
    public @ResponseBody String export(HttpServletRequest request, HttpServletResponse response,
                                       TwglStudentCorpActivity data,
                                       @RequestParam("bodyData") String bodyData,
                                       ModelMap model) throws Exception {
        try {
            Student student = (Student) request.getSession()
                .getAttribute(Constant.LOGIN_CONSOLE_USER);
            data.setCreatorid(student.getXsid());
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            if (data.getBeginTime1() == null || data.getBeginTime1().equals("")) {
            } else {
                data.setBeginTime(sdf.parse(data.getBeginTime1()));
            }
            if (data.getEndTime1() == null || data.getEndTime1().equals("")) {
            } else {
                data.setEndTime(sdf.parse(data.getEndTime1()));
            }
            BaseController.setSortByColumn(request, "createtime", "desc");
            data.setOrderField((String) request.getAttribute("orderField"));
            data.setOrderFlag((String) request.getAttribute("orderFlag"));
            List<TwglStudentCorpActivity> datalist = twglStudentCorpActivityService.export(data);

            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            String[][] title_name = { { "活动名称", "活动日期", "活动时间", "活动地点", "申请状态", "社团名称", "指导老师",
                                        "社长", "申请时间", "活动结果" } };
            String[] title_style = { "hwzs_16_bold_25", "kt_12_bold_18", "st_12_r_20", "st_12_n_20",
                                     "st_12_n_20", "st_12_n_20" };
            String fileName = "社团活动信息";
            String[] remark = { "" };
            List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
            /*   List<TwglStudentCorpActivity> datalist = JSONArray.parseArray(bodyData,
                TwglStudentCorpActivity.class);*/
            if (datalist != null && !datalist.isEmpty()) {
                for (TwglStudentCorpActivity r : datalist) {
                    Map<String, Object> map = new LinkedHashMap<String, Object>();
                    map.put("hdmc", r.getHdmc());
                    map.put("hdrq", sdf.format(r.getHdrq()));
                    map.put("hdsj", r.getHdsj());
                    map.put("hddd", r.getHddd());
                    if (r.getStates() == 1) {
                        map.put("states", "审核中");
                    } else if (r.getStates() == 0) {
                        map.put("states", "未提交");
                    } else if (r.getStates() == 2) {
                        map.put("states", "审核通过");
                    } else if (r.getStates() == 3) {
                        map.put("states", "审核退回");
                    }
                    map.put("stmc", r.getStmc());
                    map.put("zdlsxm", r.getZdlsxm());
                    map.put("szxm", r.getSzxm());
                    map.put("createtime", sdf2.format(r.getCreatetime()));
                    map.put("hdjg", "");

                    list.add(map);
                }
            }
            HSSFWorkbook wb = ExpExcelUtil.getWorkBookExcel(title_name, title_style, 100, remark,
                fileName, list);
            try {
                String filenameConvert = "社团活动信息";
                new String(fileName.getBytes("GB2312"), "ISO8859-1");
                response.reset();
                response.setContentType("application/vnd.ms-excel;charset=utf-8");
                response.setHeader("Content-Disposition",
                    "attachment;filename=" + new String((filenameConvert + ".xls").getBytes(),
                        "iso-8859-1"));
                response.setDateHeader("Expires", 0);
                ServletOutputStream os = response.getOutputStream();
                wb.write(os);
                os.flush();
            } catch (Exception e) {
                System.out.println("网络连接断开，可能用户取消了导出");
                model.addAttribute(Constant.EXPTION_MSG_KEY, e);
                return "error/error";
            }
        } catch (RPCException e) {
            LOGGER.error("获得信息 export[{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(), e.getMessage());
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
        return null;
    }

    /**
     * 管理端
     * 
     * @param model
     * @param request
     * @return
     */

    @RequestMapping(value = "/index_admin")
    public String index_admin(ModelMap model, HttpServletRequest request) {
        try {
            TwglStudentCorporation data = new TwglStudentCorporation();
            List<TwglStudentCorporation> liststmc = twglStudentCorporationService
                .getUseridstmc(data);
            model.addAttribute("liststmc", liststmc);
        } catch (Exception e) {
            e.printStackTrace();
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
        return "twglStudentCorpActivity/twglStudentCorpActivityList_admin";
    }

    @RequestMapping(value = "/List_admin")
    @ResponseBody
    public ResponseResult List_admin(ModelMap model, HttpServletRequest request,
                                     @RequestParam(value = "rows", required = false) String pageSize,
                                     @RequestParam(value = "page", required = false) String currentPage,
                                     TwglStudentCorpActivity data) {

        try {
            Page page = new Page();
            page.setCurrPage(currentPage == null ? 0 : Integer.valueOf(currentPage));
            page.setPageSize(pageSize == null ? Constant.PageSize : Integer.valueOf(pageSize));
            BaseController.setSortByColumn(request, "cc.createtime", "desc");
            data.setOrderField((String) request.getAttribute("orderField"));
            data.setOrderFlag((String) request.getAttribute("orderFlag"));
            data.setLogo("100"); // 标识管理端

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            if (data.getBeginTime1() == null || data.getBeginTime1().equals("")) {
            } else {
                data.setBeginTime(sdf.parse(data.getBeginTime1()));
            }
            if (data.getEndTime1() == null || data.getEndTime1().equals("")) {
            } else {
                data.setEndTime(sdf.parse(data.getEndTime1()));
            }

            PaginationBean<TwglStudentCorpActivity> paginationBean = twglStudentCorpActivityService
                .queryPageList(data, page);
            ResponseResult result = new ResponseResult();

            if (paginationBean.getPageList().isEmpty()) {
                result.setRows(new ArrayList<TwglStudentCorpActivity>());
            } else {
                result.setRows(paginationBean.getPageList());
            }
            result.setTotal(paginationBean.getTotalRecords());
            return result;
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
        return null;
    }

    @RequestMapping(value = "/registration_admin", method = RequestMethod.GET)
    public String registration_admin(ModelMap model, HttpServletRequest request,
                                     @RequestParam(value = "id") Integer id) {
        try {
            TwglStudentCorporation data1 = new TwglStudentCorporation();
            List<TwglStudentCorporation> liststmc = twglStudentCorporationService
                .getUseridstmc(data1);
            model.addAttribute("liststmc", liststmc);

            TwglStudentCorpActivity data = new TwglStudentCorpActivity();
            data.setHdid(id);
            data = twglStudentCorpActivityService.queryByPK(data);

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            data.setBeginTime1(sdf.format(data.getHdrq()));
            model.addAttribute("data", data);

            return "twglStudentCorpActivity/twglStudentCorpActivity_registration_admin";
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("查询 queryByPK [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(), e.getMessage());
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
    }

    /**
     * 管理端下载
     * 
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */

    @RequestMapping(value = "/export_admin")
    public @ResponseBody String export_admin(HttpServletRequest request,
                                             HttpServletResponse response,
                                             TwglStudentCorpActivity data,
                                             @RequestParam("bodyData") String bodyData,
                                             ModelMap model) throws Exception {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            if (data.getBeginTime1() == null || data.getBeginTime1().equals("")) {
            } else {
                data.setBeginTime(sdf.parse(data.getBeginTime1()));
            }
            if (data.getEndTime1() == null || data.getEndTime1().equals("")) {
            } else {
                data.setEndTime(sdf.parse(data.getEndTime1()));
            }
            BaseController.setSortByColumn(request, "cc.createtime", "desc");
            data.setOrderField((String) request.getAttribute("orderField"));
            data.setOrderFlag((String) request.getAttribute("orderFlag"));
            data.setLogo("100"); // 标识管理端
            List<TwglStudentCorpActivity> datalist = twglStudentCorpActivityService.export(data);

            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            String[][] title_name = { { "活动名称", "活动日期", "活动时间", "活动地点", "社团名称", "指导老师", "社长",
                                        "申请时间" } };
            String[] title_style = { "hwzs_16_bold_25", "kt_12_bold_18", "st_12_r_20", "st_12_n_20",
                                     "st_12_n_20", "st_12_n_20" };
            String fileName = "社团活动信息";
            String[] remark = { "" };
            List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
            /* List<TwglStudentCorpActivity> datalist = JSONArray.parseArray(bodyData,
                TwglStudentCorpActivity.class);*/
            if (datalist != null && !datalist.isEmpty()) {
                for (TwglStudentCorpActivity r : datalist) {
                    Map<String, Object> map = new LinkedHashMap<String, Object>();
                    map.put("hdmc", r.getHdmc());
                    map.put("hdrq", sdf.format(r.getHdrq()));
                    map.put("hdsj", r.getHdsj());
                    map.put("hddd", r.getHddd());
                    map.put("stmc", r.getStmc());
                    map.put("zdlsxm", r.getZdlsxm());
                    map.put("szxm", r.getSzxm());
                    map.put("createtime", sdf2.format(r.getCreatetime()));

                    list.add(map);
                }
            }
            HSSFWorkbook wb = ExpExcelUtil.getWorkBookExcel(title_name, title_style, 100, remark,
                fileName, list);
            try {
                String filenameConvert = "社团活动信息";
                new String(fileName.getBytes("GB2312"), "ISO8859-1");
                response.reset();
                response.setContentType("application/vnd.ms-excel;charset=utf-8");
                response.setHeader("Content-Disposition",
                    "attachment;filename=" + new String((filenameConvert + ".xls").getBytes(),
                        "iso-8859-1"));
                response.setDateHeader("Expires", 0);
                ServletOutputStream os = response.getOutputStream();
                wb.write(os);
                os.flush();
            } catch (Exception e) {
                System.out.println("网络连接断开，可能用户取消了导出");
                model.addAttribute(Constant.EXPTION_MSG_KEY, e);
                return "error/error";
            }
        } catch (RPCException e) {
            LOGGER.error("获得信息 export[{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(), e.getMessage());
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
        return null;
    }

    // 审核端
    @RequestMapping(value = "/index_audit")
    public String index_audit(ModelMap model, HttpServletRequest request) {
        try {
            model.addAttribute("states", 1);
            TwglStudentCorporation data = new TwglStudentCorporation();
            List<TwglStudentCorporation> liststmc = twglStudentCorporationService
                .getUseridstmc(data);
            model.addAttribute("liststmc", liststmc);
        } catch (Exception e) {
            e.printStackTrace();
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
        return "twglStudentCorpActivity/twglStudentCorpActivityList_audit";
    }

    @RequestMapping(value = "/List_audit")
    @ResponseBody
    public ResponseResult List_audit(ModelMap model, HttpServletRequest request,
                                     @RequestParam(value = "rows", required = false) String pageSize,
                                     @RequestParam(value = "page", required = false) String currentPage,
                                     TwglStudentCorpActivity data) {

        data.setLogo("99"); // 标识审核管理端
        try {
            Page page = new Page();
            page.setCurrPage(currentPage == null ? 0 : Integer.valueOf(currentPage));
            page.setPageSize(pageSize == null ? Constant.PageSize : Integer.valueOf(pageSize));

            BaseController.setSortByColumn(request, "createtime", "desc");
            if (request.getAttribute("orderField").equals("createtime")) {
                data.setOrderField("cc.CreateTime");
            } else if (request.getAttribute("orderField").equals("states")) {
                data.setOrderField("cc.states");
            } else {
                data.setOrderField((String) request.getAttribute("orderField"));
            }
            data.setOrderFlag((String) request.getAttribute("orderFlag"));

            if (data.getStates() == null || data.getStates().equals("")) {
                data.setStates(1);
            } else if (data.getStates() == -1) {
                data.setStates(null);
            }

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            if (data.getBeginTime1() == null || data.getBeginTime1().equals("")) {
            } else {
                data.setBeginTime(sdf.parse(data.getBeginTime1()));
            }
            if (data.getEndTime1() == null || data.getEndTime1().equals("")) {
            } else {
                data.setEndTime(sdf.parse(data.getEndTime1()));
            }

            PaginationBean<TwglStudentCorpActivity> paginationBean = twglStudentCorpActivityService
                .queryPageList(data, page);
            ResponseResult result = new ResponseResult();

            if (paginationBean.getPageList().isEmpty()) {
                result.setRows(new ArrayList<TwglStudentCorpActivity>());
            } else {
                result.setRows(paginationBean.getPageList());
            }
            result.setTotal(paginationBean.getTotalRecords());
            return result;
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
        return null;
    }

    @RequestMapping(value = "/details_audit", method = RequestMethod.GET)
    public String details_admin(ModelMap model, HttpServletRequest request,
                                @RequestParam(value = "id", required = false) Integer id,
                                @RequestParam(value = "gid", required = false) String gid) {
        try {

            TwglStudentCorporation data1 = new TwglStudentCorporation();
            List<TwglStudentCorporation> liststmc = twglStudentCorporationService
                .getUseridstmc(data1);
            model.addAttribute("liststmc", liststmc);

            TwglStudentCorpActivity data = new TwglStudentCorpActivity();
            data.setHdid(id);
            data = twglStudentCorpActivityService.queryByPK(data);

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            data.setBeginTime1(sdf.format(data.getHdrq()));
            model.addAttribute("data", data);

            return "twglStudentCorpActivity/twglStudentCorpActivity_registration_audit";
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("查询 queryByPK [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(), e.getMessage());
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
    }

    @SysLogger(description = "社团活动管理信息", moduleName = "社团活动管理", method = "审核")
    @RequestMapping(value = "/audit")
    public String audit(ModelMap model, HttpServletRequest request, TwglStudentCorpActivity data,
                        @RequestParam(value = "states", required = false) String states) {
        try {
            UserEmployee userEmployee = (UserEmployee) request.getSession()
                .getAttribute(Constant.LOGIN_CONSOLE_USER);

            String auditsuggestio = data.getAuditsuggestion();

            data = twglStudentCorpActivityService.queryByPK(data);
            data.setStates(Integer.valueOf(states));
            data.setAuditsuggestion(auditsuggestio);
            data.setAuditorid(userEmployee.getEmid() == null ? null : userEmployee.getEmid());
            data.setAuditorname(userEmployee.getXm());
            data.setAudittime(new Date());
            twglStudentCorpActivityService.update(data);
            return "redirect:index_audit";
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("审核 update [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(), e.getMessage());
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
    }

    @SysLogger(description = "社团活动管理信息", moduleName = "社团活动管理", method = "审核")
    @RequestMapping(value = "/auditList")
    public String auditList(ModelMap model, HttpServletRequest request) {
        try {
            UserEmployee userEmployee = (UserEmployee) request.getSession()
                .getAttribute(Constant.LOGIN_CONSOLE_USER);
            String[] idList = request.getParameter("idList").split(",");
            String states = request.getParameter("states1");

            TwglStudentCorpActivity data = new TwglStudentCorpActivity();
            data.setIds(idList);
            data.setStates(Integer.valueOf(states));
            data.setAuditorid(userEmployee.getEmid() == null ? null : userEmployee.getEmid());
            data.setAuditorname(userEmployee.getXm());
            data.setAudittime(new Date());
            twglStudentCorpActivityService.auditList(data);
            BaseController.setParameter("msg", "审核成功");
            return "redirect:index_audit";
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("审核 delete [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(), e.getMessage());
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
    }

    /**
     * 审核下载**
     * 
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/export_audit")
    public @ResponseBody String export_audit(HttpServletRequest request,
                                             HttpServletResponse response,
                                             TwglStudentCorpActivity data,
                                             @RequestParam("bodyData") String bodyData,
                                             ModelMap model) throws Exception {
        try {

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            if (data.getBeginTime1() == null || data.getBeginTime1().equals("")) {
            } else {
                data.setBeginTime(sdf.parse(data.getBeginTime1()));
            }
            if (data.getEndTime1() == null || data.getEndTime1().equals("")) {
            } else {
                data.setEndTime(sdf.parse(data.getEndTime1()));
            }
            if (data.getStates() == null || data.getStates().equals("")) {
                data.setStates(1);
            } else if (data.getStates() == -1) {
                data.setStates(null);
            }
            BaseController.setSortByColumn(request, "cc.createtime", "desc");
            data.setOrderField((String) request.getAttribute("orderField"));
            data.setOrderFlag((String) request.getAttribute("orderFlag"));
            data.setLogo("99"); // 标识审核管理端
            List<TwglStudentCorpActivity> datalist = twglStudentCorpActivityService.export(data);

            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            String[][] title_name = { { "活动名称", "活动日期", "活动时间", "活动地点", "申请状态", "社团名称", "指导老师",
                                        "社长", "申请时间" } };
            String[] title_style = { "hwzs_16_bold_25", "kt_12_bold_18", "st_12_r_20", "st_12_n_20",
                                     "st_12_n_20", "st_12_n_20" };
            String fileName = "社团活动信息";
            String[] remark = { "" };
            List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
            /*   List<TwglStudentCorpActivity> datalist = JSONArray.parseArray(bodyData,
                TwglStudentCorpActivity.class);*/
            if (datalist != null && !datalist.isEmpty()) {
                for (TwglStudentCorpActivity r : datalist) {
                    Map<String, Object> map = new LinkedHashMap<String, Object>();
                    map.put("hdmc", r.getHdmc());
                    map.put("hdrq", sdf.format(r.getHdrq()));
                    map.put("hdsj", r.getHdsj());
                    map.put("hddd", r.getHddd());
                    if (r.getStates() == 1) {
                        map.put("states", "审核中");
                    } else if (r.getStates() == 0) {
                        map.put("states", "未提交");
                    } else if (r.getStates() == 2) {
                        map.put("states", "审核通过");
                    } else if (r.getStates() == 3) {
                        map.put("states", "审核退回");
                    }
                    map.put("stmc", r.getStmc());
                    map.put("zdlsxm", r.getZdlsxm());
                    map.put("szxm", r.getSzxm());
                    map.put("createtime", sdf2.format(r.getCreatetime()));

                    list.add(map);
                }
            }
            HSSFWorkbook wb = ExpExcelUtil.getWorkBookExcel(title_name, title_style, 100, remark,
                fileName, list);
            try {
                String filenameConvert = "社团活动信息";
                new String(fileName.getBytes("GB2312"), "ISO8859-1");
                response.reset();
                response.setContentType("application/vnd.ms-excel;charset=utf-8");
                response.setHeader("Content-Disposition",
                    "attachment;filename=" + new String((filenameConvert + ".xls").getBytes(),
                        "iso-8859-1"));
                response.setDateHeader("Expires", 0);
                ServletOutputStream os = response.getOutputStream();
                wb.write(os);
                os.flush();
            } catch (Exception e) {
                System.out.println("网络连接断开，可能用户取消了导出");
                model.addAttribute(Constant.EXPTION_MSG_KEY, e);
                return "error/error";
            }
        } catch (RPCException e) {
            LOGGER.error("获得信息 export[{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(), e.getMessage());
            model.addAttribute(Constant.EXPTION_MSG_KEY, e);
            return "error/error";
        }
        return null;
    }
}
